<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">
    <ui:define name="head-title">
        <title>Edit Supplier | Merlion's ERP System</title>
    </ui:define>
    
    <ui:define name="content">
        <f:view beforePhase="#{editSupplier.initView}">
            
                <p:panel id="panel" header="Update Supplier">
                    <p:ajaxStatus style="width:16px;height:16px;">
                        <f:facet name="start">
                            <p:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" /> 
                        </f:facet>

                        <f:facet name="complete">
                            <h:outputText value=""/>
                        </f:facet>
                    </p:ajaxStatus>

                    <p:messages />
                    <h:form prependId="false" id="form1">
                        <p:fieldset legend="Supplier Detailes" style="font-weight: bold">
                            <h:panelGrid columns="3" cellpadding="10">
                                
                            <h:outputLabel for="supplierName" style="font-weight: bold" value="Supplier Name: "/>
                            <h:outputText value="#{editSupplier.supplierToEdit.supplierName}" id="supplierName"/>
                            <p:message for="supplierName"/>

                            <h:outputLabel for="supplierAddress" style="font-weight: bold" value="Supplier Address:"/>
                            <p:inputText value="#{editSupplier.supplierToEdit.supplierAddress}" id="supplierAddress"/>
                            <p:message for="supplierAddress"/>

                            <h:outputLabel for="supplierPostcode" style="font-weight: bold" value="Supplier Postcode:"/>
                            <p:inputText value="#{editSupplier.supplierToEdit.supplierPostcode}" id="supplierPostcode"/>
                            <p:message for="supplierPostcode"/>   

                            <h:outputLabel for="supplierContactNo" style="font-weight: bold" value="Supplier Contact Number:"/>
                            <p:inputText value="#{editSupplier.supplierToEdit.supplierContactNo}" id="supplierContactNo"/>
                            <p:message for="supplierContactNo"/>  

                            <h:outputLabel for="supplierEmail" style="font-weight: bold" value="Supplier Email:"/>
                            <p:inputText value="#{editSupplier.supplierToEdit.supplierEmail}" id="supplierEmail"/>
                            <p:message for="supplierEmail"/>                     
                           
                            </h:panelGrid>     
                        </p:fieldset>
                         
                        <p:spacer height="15"/>   
                        <p:separator />
                        <p:dataTable var="supplyItem" value="#{editSupplier.supplyItemList}"
                                     dynamic="true" paginator="true" emptyMessage="No Raw Material Type" 
                                     id="supplyItemTable" selection="#{editSupplier.selectedSupplyItem}">
                            <f:facet name="header">
                                Supply Item List
                            </f:facet>

                            <p:column selectionMode="single"/>

                            <p:column sortBy="#{supplyItem.supplyItemId}">
                                <f:facet name="header">
                                    <h:outputText value="Supply Item ID"/>
                                </f:facet>
                                <h:outputText value="#{supplyItem.supplyItemId}"/>
                            </p:column>   

                            <p:column sortBy="#{supplyItem.supplyItemType}">
                                <f:facet name="header">
                                    <h:outputText value="Type"/>
                                </f:facet>
                                <h:outputText value="#{supplyItem.supplyItemType}"/>
                            </p:column>

                            <p:column sortBy="#{supplyItem.supplyItemPrice}">
                                <f:facet name="header">
                                    <h:outputText value="Price"/>
                                </f:facet>
                                <h:inputText value="#{supplyItem.supplyItemPrice}"/>
                            </p:column>

                        </p:dataTable>
                        <p:commandButton value="Add New Supply Item" onclick ="addSupplyItemDialog.show()" ajax="true"/>
                        <p:commandButton value="Delete Supply Item" onclick="confirmation.show()" type="button"/>

                        <p:commandButton id="btn" value="Update Supplier" update="panel" actionListener="#{editSupplier.updateSupplier}" ajax="true"/>
                        
                        
                        <p:confirmDialog message="Are you sure about deleting this Supply Item? "
                                         showEffect="bounce" hideEffect="explode"
                                         header="Initiating delete process" severity="alert" widgetVar="confirmation">
                            <p:commandButton value="Yes" actionListener="#{editSupplier.deleteSupplyItem}"
                                             update="panel supplyItemTable" oncomplete="confirmation.hide()"/>
                            <p:commandButton value="No" onclick="confirmation.hide()" type="button"/>
                        </p:confirmDialog>                         
                    </h:form>

                    <h:form prependId="false">
                        <p:dialog header="Add New Supply Item" widgetVar="addSupplyItemDialog" width="400" height="400" resizable="true" showEffect="clip" hideEffect="fold">
                            <h:panelGrid id="display" columns="2">
                                
                                <h:outputText value="Supply Item Type:"/>
                                <h:selectOneMenu id="supplyItemType" value="#{editSupplier.newSi.supplyItemType}">
                                    <f:selectItem itemLabel="Select Raw Material Type " itemValue="" />
                                    <f:selectItems value="#{editSupplier.materials}"/>
                                </h:selectOneMenu>  
                                
                                <h:outputText value="Supply Item Price:"/>
                                <p:inputText value="#{editSupplier.newSi.supplyItemPrice}" required="true"/>
                                <p:commandButton value="Add" actionListener="#{editSupplier.addSupplyItem}" update="panel supplyItemTable" oncomplete="addSupplyItemDialog.hide()"/>  
                            </h:panelGrid>
                        </p:dialog>
                    </h:form>

                </p:panel>

          </f:view>
     </ui:define>
</ui:composition>
